package com.woniuxy.training.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 日期转换工具类
 */
public class DateUtil {
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    public static Date after(Date start,int unit,int time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(start);
        calendar.add(unit, time);
        return calendar.getTime();
    }
    /**
     * 字符串转日期
     * @param str
     * @return
     */
    public static Date string2Date(String str) {

        Date date = null;
        try {
            date = sdf.parse(str);

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
    /**
     * 日期转换字符串
     * @param date
     * @return
     */
    public static String date2String(Date date) {
        String str = sdf.format(date);
        return str;
    }
}
